loadstring(exports.dgs:dgsImportFunction())()

cmtaZAROBEK = false
local sw,sh = guiGetScreenSize()
local px,py = sw/1366,sh/768
local number = 0
font = dgsCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 12*px )

local last = {}
last.antyspam = {}

function panel()
    if not getElementData(localPlayer,"player:data").uid then return end
    if isConsoleActive() then return end
        if cmtaZAROBEK == true then
            if dgsGetEnabled(rect1) == false then return end
            removeEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
            removeEventHandler ( "onClientRender", getRootElement(), onrender)
            cmtaZAROBEK = false 
            showCursor(false)
            destroyElement(rndRect)
            destroyElement(rect1)
        else
            triggerServerEvent("cmta_zarabianie:get_info", resourceRoot)
            rndRect = dgsCreateRoundRect(30,false,tocolor(0,0,0,190))  
            rect1 = dgsCreateImage(400*px,150*py,566*px,468*py,rndRect,false)
            dgsSetAlpha(rect1,0)
            dgsSetVisible ( rect1,true )
            image = dgsCreateImage(142*px,100*py,290*px,182*py,"click.png",false,rect1,tocolor(255,255,255,255))
            text = dgsCreateLabel(0*px,310*py,566*px,50*py,"",false,rect1)
            dgsSetFont( text, font )
            dgsSetProperty(text,"colorcoded",true)
            dgsSetProperty(text,"alignment",{"center","center"})

            text2 = dgsCreateLabel(0*px,30*py,566*px,50*py,"Naciskaj #00ff00lewy przycisk myszy#ffffff, aby zdobyć punkty",false,rect1)
            dgsSetFont( text2, font )
            dgsSetProperty(text2,"colorcoded",true)
            dgsSetProperty(text2,"alignment",{"center","center"})

            button = dgsCreateButton( 20*px, 400*py, 226*px, 40*py, "Ulepszenia", false,rect1,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            button5 = dgsCreateButton( 320*px, 400*py, 226*px, 40*py, "Odbierz punkty", false,rect1,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))

            progress = dgsCreateProgressBar(442*px,100*py,30*px,182*py,false,rect1,false,false,false,tocolor(210,105,30),true) 
            dgsProgressBarSetStyle(progress,"normal-vertical")
            addEventHandler ( "onDgsMouseClick", getRootElement(), onclick)
            addEventHandler ( "onClientRender", getRootElement(), onrender)
            showCursor(true)
            cmtaZAROBEK = true
            dgsAlphaTo(rect1,255,false,"OutQuad",2000)
            if getElementData(localPlayer,"player:data").lvl < 100 then
                mnoznik = 50
            elseif getElementData(localPlayer,"player:data").lvl >= 100 and getElementData(localPlayer,"player:data").lvl < 200 then
                mnoznik = 35
            elseif getElementData(localPlayer,"player:data").lvl >= 200 and getElementData(localPlayer,"player:data").lvl < 300 then
                mnoznik = 30
            elseif getElementData(localPlayer,"player:data").lvl >= 300 and getElementData(localPlayer,"player:data").lvl < 400 then
                mnoznik = 20
            elseif getElementData(localPlayer,"player:data").lvl >= 400 then
                mnoznik = 15
            end
        end
end
bindKey ("F2", "down", panel)

function onclick ( btn, state )
    if btn == "left" and state == "down" and cmtaZAROBEK == true then
        if source == image then
            local maxclicks = 2000+(mnoznik*getElementData(localPlayer,"player:data").lvl)
            if ilosc_klikniec >= maxclicks then return end
            timer = timer or 0 
            timerb = getTickCount()
            if timer > timerb then return end
            timer = getTickCount()+getElementData(localPlayer,"player:data").timemultiplier
            local los = math.random(1,500)
            if los == 214 then
                exports["cmta-antybot"]:antybot(localPlayer) 
            end 
            numbernew = dgsProgressBarGetProgress(progress)
                if getElementData(localPlayer,"player:hotbonus") ~= true then
                if numbernew >= 100 then
                    local amount = (getElementData(localPlayer,"player:data").gainscore/1000)*2
                    local time = (getElementData(localPlayer,"player:data").timemultiplier/1000)*0.7
                    refresh(amount,time)
                    dgsImageSetImage(image, dxCreateTexture("clickfire.png"))
                    setTimer(function()
                        refresh(getElementData(localPlayer,"player:data").gainscore/1000,getElementData(localPlayer,"player:data").timemultiplier/1000)
                        dgsImageSetImage(image, dxCreateTexture("click.png"))
                        setElementData(localPlayer,"player:hotbonus",nil)
                    end,30000,1)
                    dgsProgressBarSetProgress(progress,0)
                    setElementData(localPlayer,"player:hotbonus",true)
                    elseif numbernew < 100 then
                    dgsProgressBarSetProgress(progress,(numbernew or number)+0.1)
                end
                end
                triggerServerEvent("cmta_zarabianie:punkty", resourceRoot,amount)
                exports["cmta-systemleveli"]:giveexp(math.random(1,2),localPlayer)
        end
        if source == button then 
            dgsSetEnabled(rect1,false)
            window = dgsCreateWindow(300*px,200*py,766*px,368*py,"panel ulepszeń",false,false,false,false,tocolor(210,105,30),false,false,false,true)
            dgsWindowSetMovable ( window, false )
            dgsWindowSetSizable ( window, false )
            text2 = dgsCreateLabel(50*px,90*py,266*px,50*py,"",false,window)
            text3 = dgsCreateLabel(250*px,90*py,666*px,50*py,"",false,window)
            button2 = dgsCreateButton( 50*px, 210*py, 266*px, 40*py, "Ulepsz", false,window,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            button3 = dgsCreateButton( 450*px, 210*py, 266*px, 40*py, "Ulepsz", false,window,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))
            button4 = dgsCreateButton( 250*px, 280*py, 266*px, 40*py, "Zamknij", false,window,false,false,false,false,false,false,false,tocolor(90,90,90),tocolor(255,0,0,90))

            dgsSetFont( text2, font )
            dgsSetProperty(text2,"colorcoded",true)
            dgsSetProperty(text2,"alignment",{"center","center"})
            dgsSetFont( text3, font )
            dgsSetProperty(text3,"colorcoded",true)
            dgsSetProperty(text3,"alignment",{"center","center"})
            updatetext()
        end
        
        if source == button2 then
        if ulep1 >= 40 then return end
        if getElementData(localPlayer,"player:data").points < priceulep then 
        exports["cmta-notyfikacje"]:add("Posiadasz za mało punktów na ulepszenie.", 3000, 10, tocolor(255, 255, 255), tocolor(255,0,0, 155))
        return end
        triggerServerEvent("cmta:zarabianie:ulepsz", resourceRoot,"1",tonumber(priceulep))
        end

        if source == button3 then
            if ulep3 >= 40 then return end
            if getElementData(localPlayer,"player:data").points < priceulep2 then 
            exports["cmta-notyfikacje"]:add("Posiadasz za mało punktów na ulepszenie.", 3000, 10, tocolor(255, 255, 255), tocolor(255,0,0, 155))
            return end
            triggerServerEvent("cmta:zarabianie:ulepsz", resourceRoot,"2",tonumber(priceulep2))
        end

        if source == button4 then
            destroyElement(window)
            dgsSetEnabled(rect1,true)
        end

        if source == button5 then
            if last.antyspam[localPlayer] and last.antyspam[localPlayer] >= getTickCount()-5000 then exports['cmta-notyfikacje']:sendNotification("#ccc000Informacja\n#ffffffPoczekaj chwilę...","info",3000) return end 
            triggerServerEvent("cmta_zarabianie:odbierzpunkty", resourceRoot)
            last.antyspam[localPlayer] = getTickCount()
        end
    end
end

function refresh(res1,res2)
amount = res1
time = res2
end

function onrender()
local maxclicks = 2000+(mnoznik*getElementData(localPlayer,"player:data").lvl)
dgsSetText(text,"#808080Kliknięcia: #ff0000 "..(ilosc_klikniec or 0).."/"..(maxclicks or 0).."\n#808080wartość: #ff0000"..(amount or getElementData(localPlayer,"player:data").gainscore/1000).." pkt\n#808080czas odnowy: #ff0000"..(time or getElementData(localPlayer,"player:data").timemultiplier/1000).." sec\n#808080Punkty do odbioru: #ff0000"..(string.format("%.1f",ilosc_punktow or 0)).."")
end

addEvent("cmta:zarabianie:refresh", true)
addEventHandler("cmta:zarabianie:refresh", resourceRoot, function(result)
updatetext()
end)

addEvent("cmta_zarabianie:info", true)
addEventHandler("cmta_zarabianie:info", resourceRoot, function(var1,var2)
ilosc_punktow = var1
ilosc_klikniec = var2
end)



function updatetext()
    local points = getElementData(localPlayer,"player:data").gainscore
    local time = getElementData(localPlayer,"player:data").timemultiplier
    
    local ulep = points-1000
    ulep1 = ulep/100
    if ulep1 == 0 then
    priceulep = 500
    elseif ulep1 < 20 then
    priceulep = ulep1*800
    elseif ulep1 >=20 and ulep1 < 30 then
    priceulep = ulep1*1200
    else
    priceulep = ulep1*1600
    end
    
    local ulep2 = 1000-time
    ulep3 = ulep2/20
    if ulep3 == 0 then
    priceulep2 = 350
    elseif ulep3 < 20 then
    priceulep2 = ulep3*650
    elseif ulep3 >=20 and ulep3 < 30 then
    priceulep2 = ulep3*950
    else
    priceulep2 = ulep3*1250
    end

    dgsSetText(text2,"#ff2828ZWIĘKSZENIE WARTOŚCI KLIKNIĘCIA\n\n#808080Aktualna wartość: #ff2828"..(points/1000).."#ccc000+0.1\n#808080Ulepszenia #ff2828"..ulep1.."/40\n#808080Koszt ulepszenia: #ff2828"..priceulep.." pkt")
    dgsSetText(text3,"#ff2828ZMNIEJSZENIE CZASU ODNOWY\n\n#808080Aktualna wartość: #ff2828"..(time/1000).."#ccc000-0.2\n#808080Ulepszenia #ff2828"..ulep3.."/40\n#808080Koszt ulepszenia: #ff2828"..priceulep2.." pkt")
end

local cspam = {} 
function antyspam()
    if cmtaZAROBEK == true then return end
    if (not cspam[localPlayer]) then 
        cspam[localPlayer] = 1 
    else 
        cspam[localPlayer] = cspam[localPlayer] + 1 
    end 
	if (cspam[localPlayer] >= 24) then
	cancelEvent()
    triggerServerEvent("cmta_zarabianie:kick", resourceRoot)
    end
    if (cspam[localPlayer] >= 22) and (cspam[localPlayer] < 24) then 
        cancelEvent() 
        outputChatBox("#ff0000[ANTYCHEAT] #808080Przestań spamić klikaniem!", 255, 0, 0,true) 	
	end
end 
addEventHandler("onClientClick",root,antyspam)
setTimer(function() cspam = {} end, 1000, 0) 